package com.andy.buyu.server.action;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.andy.buyu.server.entity.UsrGameLog;
import com.andy.buyu.server.game.FishGame;
import com.andy.buyu.server.game.GameUser;
import com.andy.buyu.server.socket.GmAction;
import com.andy.buyu.server.socket.MySocketSession;
import com.andy.buyu.server.socket.SendUtil;
import com.andy.buyu.server.socket.codec.DataWrap;
import com.andy.buyu.server.utils.CommonUtils;

/**
 * 捕鱼逻辑
 * @author cuiwm
 *
 */
@Component(GmAction.ACTION_PREFIX+GmAction.ACTION_202)
public class Action202 implements IReqAction{

	private static Logger logger = LoggerFactory.getLogger(Action202.class);
	
	@Override
	public void doAction(MySocketSession session, DataWrap data) {
		GameUser user = session.getUser();
		int bullet = data.getByte();
		int scriptId = data.getInt();
		FishGame game = user.getGame();
		if(game == null) return;
		if(logger.isInfoEnabled()){
			logger.info("202:{}-{}-{}", user.getId(),bullet,scriptId);
		}
		if(!user.catchFish(bullet,scriptId)) return ;
		
		UsrGameLog log = CommonUtils.catchFish(user,game, scriptId, bullet,0);
		if(log != null && log.getRate() >= 0){
			if(log.battary() > 0){
				if(logger.isInfoEnabled()){
					logger.info("切换炮台：{}-{}", user.getId(),log.battary());
				}
				SendUtil.send202(user.getRoom(),bullet, log,user);
				// 由前端触发
//				SendUtil.send203(user);
			}else {
				SendUtil.send202(user.getRoom(),bullet, log,null);
			}
		}
		
	}


	
}
